package com.ideal.hbase.client.thread;

import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.util.List;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.util.Bytes;


public class HbaseUtils {
	private static Configuration conf = HBaseConfiguration.create();
	/*private static String tableName;
	private static String rowkey;*/
	
	
	static{
		conf.set("hbase.zookeeper.property.clientPort", "2182");
		conf.set("hbase.zookeeper.quorum", "180.101.144.29");
		conf.set("zookeeper.znode.parent", "/hbase");
		conf.set("hbase.rpc.timeout", "5000");
		conf.set("hbase.client.operation.timeout", "5000");
		conf.set("hbase.ipc.client.socket.timeout.read", "5000");
		conf.set("hbase.ipc.client.socket.timeout.write", "5000");
	}
	public static void dataInsert(String tableName,String rowkey,String family,String qualifier,String value){
		try {
			
			HTable hTable = new HTable(conf, tableName);
			byte[] row = Bytes.toBytes(rowkey);
			Put put = new Put(row);
			byte[] fam = Bytes.toBytes(family);
			byte[] qual = Bytes.toBytes(qualifier);
			byte[] val = Bytes.toBytes(value);
			
			put.addColumn(fam, qual,val);
			
			hTable.put(put);
			
			hTable.close();

		
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}
	
	/*public static void batchInsert(List<InsertData> insertDataList,String tableName){
		try {
			
			
			HTable hTable = new HTable(conf, tableName);
			for (InsertData insertData : insertDataList) {
				byte[] row = Bytes.toBytes(insertData.getRowkey());
				Put put = new Put(row);
				byte[] fam = Bytes.toBytes(insertData.getFamily());
				byte[] qual = Bytes.toBytes(insertData.getQualifier());
				byte[] val = Bytes.toBytes(insertData.getValue());
				
				put.addColumn(fam, qual,val);
				
				hTable.put(put);
				
			}
			
			
			hTable.close();

		
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}*/
	
/*	 private ByteBuffer encodeQualifier(byte type, String applicationId, String agentId, long agentStartTime, long spanId, SpanEventBo firstEvent) {
	        final Buffer buffer = new AutomaticBuffer(128);
	        buffer.putByte(type);
	        buffer.putPrefixedString(applicationId);
	        buffer.putPrefixedString(agentId);
	        buffer.putVLong(agentStartTime);
	        buffer.putLong(spanId);

	        if (firstEvent != null) {
	            buffer.putSVInt(firstEvent.getSequence());

	            final byte bitField = SpanEventQualifierBitField.buildBitField(firstEvent);
	            buffer.putByte(bitField);
	            // case : async span
	            if (SpanEventQualifierBitField.isSetAsync(bitField)) {
	                buffer.putInt(firstEvent.getAsyncId());
	                buffer.putVInt(firstEvent.getAsyncSequence());
	            }
	        } else {
	            // simple trace case
//	            buffer.putSVInt((short) -1);

//	            byte cfBitField = SpanEventQualifierBitField.setAsync((byte) 0, false);
//	            buffer.putByte(cfBitField);
	        }

	        return buffer.wrapByteBuffer();
	    }*/
}
